package com.mb.app.controller;


import com.mb.app.domain.TbUserAuthInfo;
import com.mb.app.service.ITbUserAuthInfoService;
import com.mb.common.controller.BaseController;
import com.mb.common.utils.DateUtils;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author zwl
 * @program
 * @description 认证审核管理
 * @date 2019-03-25 9:30
 **/
@Controller
@RequestMapping("/app/userAuth")
@Slf4j
public class UserAuthController extends BaseController {
    

    @Autowired
    private ITbUserAuthInfoService userAuthInfoService;

    @GetMapping("/index")
    String index(Model model){
        return "/app/userAuth/userAuth_list";
    }


    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数据
        // 时间截取
        String createTime = (String) params.get("createTime");
        if (StringUtils.isNotEmpty(createTime)) {
            params.put("startTime", DateUtils.parse(createTime.substring(0,10),DateUtils.DATE_PATTERN));
            params.put("endTime",createTime.substring(13,23)+" 23:59:59");
        }
        Query query = new Query(params);
        List<TbUserAuthInfo> list = userAuthInfoService.queryList(query);
        int total = userAuthInfoService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }


    @GetMapping("/dtl/{Id}")
    String dtl(@PathVariable("Id") Long Id, Model model){
        model.addAttribute("userAuthInfo",userAuthInfoService.getDtl(Id));
        return "/app/userAuth/userAuth_info";
    }



    @GetMapping("/edit/{Id}")
    String edit(@PathVariable("Id") Long Id, Model model){
        model.addAttribute("userAuthInfo",userAuthInfoService.getDtl(Id));
        return "/app/userAuth/userAuth_edit";
    }


    @ResponseBody
    @PostMapping("/update")
    public R update(TbUserAuthInfo TbUserAuthInfo, HttpServletRequest request){
        TbUserAuthInfo.setAuditUserId(getUserId());
        int result = userAuthInfoService.update(TbUserAuthInfo);
        return R.ok();
    }

}
